import { gedanController } from "@/api/cloudbase-user-action-log";
import { isLogin } from "@/utils/user";
export default {
  namespaced: true,
  state() {
    return {
      data: { title: "我的收藏", list: [] },
    };
  },
  getters: {
    list: (state) => {
      return state.data.list;
    },
    id: (state) => {
      return state.data.id;
    },
  },
  mutations: {
    SET_DATA: (state, data) => {
      state.data = data;
    },
  },
  actions: {
    async init({ commit, state }, payload = { changed: false }) {
      if (!isLogin()) {
        return state.data;
      }
      if (state.data.id && !payload.changed) {
        return state.data;
      }
      try {
        const res = await gedanController.getShouCang();

        commit("SET_DATA", res);
        return res;
      } catch (error) {
        // gedanController.add("我的收藏", "我的收藏");
        return state.data;
      }
    },
  },
};
